<?php
/**
 * Object Relational Persistence Mapping Class for table: rad_additional_service
 *
 * @package	com.athena
 * @author	LHV
 */
class RadAdditionalService extends ORDataObject {

	/**#@+
	 * Fields of table: rad_additional_service mapped to class members
	 */
	var $rad_additional_service_id  = '';
	var $enum_paraclinic_type	    = '';
	var $vi_name					= '';
	var $en_name					= '';
	var $price		                = '';
	var $enabled                   	= '';
	/**#@-*/


	/**
	 * DB Table
	 */
	var $_table = 'rad_additional_service';

	/**
	 * Primary Key
	 */
	var $_key = 'rad_additional_service_id';

	/**
	 * Internal Name
	 */
	var $_internalName = 'RadAdditionalService';

	/**
	 * Handle instantiation
	 */
	function RadAdditionalService() {
		parent::ORDataObject();
	}

    public function getServicesByType($enumRadType) {
        $field      =   L10nHelper::getLocale();
        $field		=	L10nHelper::changeField($field, "name");
        $ds =& new Datasource_sql();
        $sql = array(
            'cols'  => "rad_additional_service_id id, $field as name",
            'from'  => "$this->_table",
            'where' => "enum_paraclinic_type = '$enumRadType' AND enabled != 0",
            'orderby' => "name"
            );
        $ds->setup($this->_db, $sql);

        return $ds->toArray('id', 'name');
    }

    public function getServicesByRadItem($enumRadType, $radTicketItemId) {
        $field      =   L10nHelper::changeField(L10nHelper::getLocale(), 'name');
        $ds =& new Datasource_sql();
        $sql = array(
            'cols'  => "t.rad_additional_service_id id, t.$field as name, ri.rad_additional_service_item_id",
            'from'  => "$this->_table t
                        LEFT JOIN rad_additional_service_item ri ON (t.rad_additional_service_item=ri.rad_additional_service_item)
                        ",
            'where' => " t.enum_paraclinic_type = '$enumRadType' AND t.enabled != 0 AND ri.rad_ticket_item_id='$radTicketItemId'",
            'orderby' => "l.$field"
            );
        $ds->setup($this->_db, $sql);

        return $ds->toArray();
    }

    public function getPrice() {
    	return $this->price;
    }
	
    //TODO localization
    public function getName() {
    	return $this->name;
    }

    public function getRadServicesByStatus ($enabled = false) {
        $field      =   L10nHelper::getLocale();
        $field		=	L10nHelper::changeField($field,"name");
        $ds =& new Datasource_sql();
        $sql = array(
            'cols'  => "rad_additional_service_id id, $field as name, price, enum_paraclinic_type, enabled",
            'from'  => "$this->_table",
            'orderby' => "name"
            );
        if ($enabled !== false) {
            $sql['where']   =   "enabled='$enabled'";
        }
        $ds->setup($this->_db, $sql);

        return $ds->toArray();
    }

}
?>
